%func:@使用Dipole计算圆柱形磁铁时的被积函数
%inpt:@R:圆柱底面半径
%     @h:圆柱高度
%     @(xd,yd,zd)被计算的位置
%     @axis 磁化方向
%oupt:@B = [Bx;By;Bz]
%note:
%date:2021-07-05 by xiyin,li in Hust;
%@Copyright 2021 Xiyin,li.
function B = PMDipCir(R,h,position,axis)
xd = position(1);
yd = position(2);
zd = position(3);
Br = 1.465;
V = pi*R^2*h;
nu0 = 4*pi*10^(-7);
switch axis
    case 'z'
        M = [0;0;1]*(Br*V)/nu0;
    case 'y'
        M = [0;1;0]*(Br*V)/nu0;
end
r = [xd;yd;zd];
D = norm(r);
B = (nu0/(4*pi*D^3))*((3*r*r'/(D^2))-eye(3))*M;
end

